package com.coda.service.impl;

import com.coda.context.BaseContext;
import com.coda.mapper.WordMapper;
import com.coda.mapper.WordSettingMapper;
import com.coda.pojo.WordSetting;
import com.coda.service.WordSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 默写设置实现类
 */
@Service
public class WordSettingServiceImpl implements WordSettingService {

    @Autowired
    private WordSettingMapper wordSettingMapper;

    /**
     * 添加默写设置
     * @param wordSetting
     * @return
     */
    @Override
    public int setWordSetting(WordSetting wordSetting) {
        //先删除以前的设置
        wordSettingMapper.delete(BaseContext.getCurrentId());
        //设置属性添加设置
        wordSetting.setUserId(BaseContext.getCurrentId());
        int result = wordSettingMapper.add(wordSetting);
        return result;
    }

    /**
     * 删除单词设置
     * @return
     */
    @Override
    public int deleteWordSetting() {
        int result = wordSettingMapper.delete(BaseContext.getCurrentId());
        return result;
    }

    /**
     * 获取当前用户的单词设置
     * @param currentId
     * @return
     */
    @Override
    public WordSetting getSetting(Integer currentId) {
        return wordSettingMapper.getByUserId(currentId);
    }
}
